package com.augurit.gzcgwsp.smartformCsdlwj.convert;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwHwShljqsForFx;
import com.augurit.gzcgwsp.smartformCsdlwj.entity.YwHwShljqs;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;

/**
 * 道路挖掘 目前这个类，只有与方欣的数据交换用到
 * @author Administrator
 *
 */

public class YwHwShljqsConvertor {
    public static ShljqsForm convertVoToForm(YwHwShljqs entity) {
        if (entity == null) return null;
        ShljqsForm form = new DozerBeanMapper().map(entity, ShljqsForm.class);        
        return form;
    }
    
    public static void convertFormToQyxxForm(ShljqsForm form, YwComQyxxForm qyxxForm) {
        if (form == null) return;
        if (qyxxForm == null) qyxxForm = new YwComQyxxForm();

        new DozerBeanMapper().map(form, qyxxForm);
        if(StringUtils.isNotBlank(form.getQybh())){
        	qyxxForm.setId(Long.parseLong(form.getQybh()));
        }
    }

    public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, ShljqsForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new ShljqsForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQybh(qyxxForm.getId().toString());
    }
    
    public static void convertFormToVo(ShljqsForm form, YwHwShljqs entity) {
        if (form == null) return;
        if (entity == null) entity = new YwHwShljqs();
        
        new DozerBeanMapper().map(form, entity);
    }
    
    public static List<ShljqsForm> convertVoListToFormList(List<YwHwShljqs> ywHwShljqsList) {
        if(ywHwShljqsList != null && ywHwShljqsList.size() > 0) {
            List<ShljqsForm> shljqsFormList = new ArrayList();
            for(int i=0; i<ywHwShljqsList.size(); i++) {
            	shljqsFormList.add(convertVoToForm(ywHwShljqsList.get(i)));
            }
            return shljqsFormList;
        }
        return null;
    }
    
    public static List<YwHwShljqs> convertFormListToVoList(List<ShljqsForm> shljqsFormList) {
        if(shljqsFormList != null && shljqsFormList.size() > 0) {
            List<YwHwShljqs> ywHwShljqsList = new ArrayList();
            for(int i=0; i<shljqsFormList.size(); i++) {
                YwHwShljqs ywHwShljqs = new YwHwShljqs();
                convertFormToVo(shljqsFormList.get(i), ywHwShljqs);
                ywHwShljqsList.add(ywHwShljqs);
            }
            return ywHwShljqsList;
        }
        return null;
    }
    
    public static void convertFormToYwHwShljqsForFx(ShljqsForm form, YwHwShljqsForFx entity) {
        if (form == null) return;
        if (entity == null) entity = new YwHwShljqsForFx();        
        new DozerBeanMapper().map(form, entity);
    }
}